home *** CD-ROM | disk | FTP | other *** search
/ Aminet 50 / Aminet 50 (2002)(GTI - Schatztruhe)[!][Aug 2002].iso / Aminet / dev / gcc / ppc-mos-gcc.lha / info / gcc.info-11 (.txt) < prev    next >
GNU Info File  |  2002-06-18  |  50KB  |  840 lines

  1. This is Info file gcc.info, produced by Makeinfo version 1.68 from the
  2. input file ./gcc.texi.
  3. INFO-DIR-SECTION Programming
  4. START-INFO-DIR-ENTRY
  5. * gcc: (gcc).                  The GNU Compiler Collection.
  6. END-INFO-DIR-ENTRY
  7.    This file documents the use and the internals of the GNU compiler.
  8.    Published by the Free Software Foundation 59 Temple Place - Suite 330
  9. Boston, MA 02111-1307 USA
  10.    Copyright (C) 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
  11. 1999, 2000 Free Software Foundation, Inc.
  12.    Permission is granted to make and distribute verbatim copies of this
  13. manual provided the copyright notice and this permission notice are
  14. preserved on all copies.
  15.    Permission is granted to copy and distribute modified versions of
  16. this manual under the conditions for verbatim copying, provided also
  17. that the sections entitled "GNU General Public License" and "Funding
  18. for Free Software" are included exactly as in the original, and
  19. provided that the entire resulting derived work is distributed under
  20. the terms of a permission notice identical to this one.
  21.    Permission is granted to copy and distribute translations of this
  22. manual into another language, under the above conditions for modified
  23. versions, except that the sections entitled "GNU General Public
  24. License" and "Funding for Free Software", and this permission notice,
  25. may be included in translations approved by the Free Software Foundation
  26. instead of in the original English.
  27. File: gcc.info,  Node: Type Attributes,  Next: Alignment,  Prev: Variable Attributes,  Up: C Extensions
  28. Specifying Attributes of Types
  29. ==============================
  30.    The keyword `__attribute__' allows you to specify special attributes
  31. of `struct' and `union' types when you define such types.  This keyword
  32. is followed by an attribute specification inside double parentheses.
  33. Three attributes are currently defined for types: `aligned', `packed',
  34. and `transparent_union'.  Other attributes are defined for functions
  35. (*note Function Attributes::.) and for variables (*note Variable
  36. Attributes::.).
  37.    You may also specify any one of these attributes with `__' preceding
  38. and following its keyword.  This allows you to use these attributes in
  39. header files without being concerned about a possible macro of the same
  40. name.  For example, you may use `__aligned__' instead of `aligned'.
  41.    You may specify the `aligned' and `transparent_union' attributes
  42. either in a `typedef' declaration or just past the closing curly brace
  43. of a complete enum, struct or union type *definition* and the `packed'
  44. attribute only past the closing brace of a definition.
  45.    You may also specify attributes between the enum, struct or union
  46. tag and the name of the type rather than after the closing brace.
  47. `aligned (ALIGNMENT)'
  48.      This attribute specifies a minimum alignment (in bytes) for
  49.      variables of the specified type.  For example, the declarations:
  50.           struct S { short f[3]; } __attribute__ ((aligned (8)));
  51.           typedef int more_aligned_int __attribute__ ((aligned (8)));
  52.      force the compiler to insure (as far as it can) that each variable
  53.      whose type is `struct S' or `more_aligned_int' will be allocated
  54.      and aligned *at least* on a 8-byte boundary.  On a Sparc, having
  55.      all variables of type `struct S' aligned to 8-byte boundaries
  56.      allows the compiler to use the `ldd' and `std' (doubleword load and
  57.      store) instructions when copying one variable of type `struct S' to
  58.      another, thus improving run-time efficiency.
  59.      Note that the alignment of any given `struct' or `union' type is
  60.      required by the ANSI C standard to be at least a perfect multiple
  61.      of the lowest common multiple of the alignments of all of the
  62.      members of the `struct' or `union' in question.  This means that
  63.      you *can* effectively adjust the alignment of a `struct' or `union'
  64.      type by attaching an `aligned' attribute to any one of the members
  65.      of such a type, but the notation illustrated in the example above
  66.      is a more obvious, intuitive, and readable way to request the
  67.      compiler to adjust the alignment of an entire `struct' or `union'
  68.      type.
  69.      As in the preceding example, you can explicitly specify the
  70.      alignment (in bytes) that you wish the compiler to use for a given
  71.      `struct' or `union' type.  Alternatively, you can leave out the
  72.      alignment factor and just ask the compiler to align a type to the
  73.      maximum useful alignment for the target machine you are compiling
  74.      for.  For example, you could write:
  75.           struct S { short f[3]; } __attribute__ ((aligned));
  76.      Whenever you leave out the alignment factor in an `aligned'
  77.      attribute specification, the compiler automatically sets the
  78.      alignment for the type to the largest alignment which is ever used
  79.      for any data type on the target machine you are compiling for.
  80.      Doing this can often make copy operations more efficient, because
  81.      the compiler can use whatever instructions copy the biggest chunks
  82.      of memory when performing copies to or from the variables which
  83.      have types that you have aligned this way.
  84.      In the example above, if the size of each `short' is 2 bytes, then
  85.      the size of the entire `struct S' type is 6 bytes.  The smallest
  86.      power of two which is greater than or equal to that is 8, so the
  87.      compiler sets the alignment for the entire `struct S' type to 8
  88.      bytes.
  89.      Note that although you can ask the compiler to select a
  90.      time-efficient alignment for a given type and then declare only
  91.      individual stand-alone objects of that type, the compiler's
  92.      ability to select a time-efficient alignment is primarily useful
  93.      only when you plan to create arrays of variables having the
  94.      relevant (efficiently aligned) type.  If you declare or use arrays
  95.      of variables of an efficiently-aligned type, then it is likely
  96.      that your program will also be doing pointer arithmetic (or
  97.      subscripting, which amounts to the same thing) on pointers to the
  98.      relevant type, and the code that the compiler generates for these
  99.      pointer arithmetic operations will often be more efficient for
  100.      efficiently-aligned types than for other types.
  101.      The `aligned' attribute can only increase the alignment; but you
  102.      can decrease it by specifying `packed' as well.  See below.
  103.      Note that the effectiveness of `aligned' attributes may be limited
  104.      by inherent limitations in your linker.  On many systems, the
  105.      linker is only able to arrange for variables to be aligned up to a
  106.      certain maximum alignment.  (For some linkers, the maximum
  107.      supported alignment may be very very small.)  If your linker is
  108.      only able to align variables up to a maximum of 8 byte alignment,
  109.      then specifying `aligned(16)' in an `__attribute__' will still
  110.      only provide you with 8 byte alignment.  See your linker
  111.      documentation for further information.
  112. `packed'
  113.      This attribute, attached to an `enum', `struct', or `union' type
  114.      definition, specified that the minimum required memory be used to
  115.      represent the type.
  116.      Specifying this attribute for `struct' and `union' types is
  117.      equivalent to specifying the `packed' attribute on each of the
  118.      structure or union members.  Specifying the `-fshort-enums' flag
  119.      on the line is equivalent to specifying the `packed' attribute on
  120.      all `enum' definitions.
  121.      You may only specify this attribute after a closing curly brace on
  122.      an `enum' definition, not in a `typedef' declaration, unless that
  123.      declaration also contains the definition of the `enum'.
  124. `transparent_union'
  125.      This attribute, attached to a `union' type definition, indicates
  126.      that any function parameter having that union type causes calls to
  127.      that function to be treated in a special way.
  128.      First, the argument corresponding to a transparent union type can
  129.      be of any type in the union; no cast is required.  Also, if the
  130.      union contains a pointer type, the corresponding argument can be a
  131.      null pointer constant or a void pointer expression; and if the
  132.      union contains a void pointer type, the corresponding argument can
  133.      be any pointer expression.  If the union member type is a pointer,
  134.      qualifiers like `const' on the referenced type must be respected,
  135.      just as with normal pointer conversions.
  136.      Second, the argument is passed to the function using the calling
  137.      conventions of first member of the transparent union, not the
  138.      calling conventions of the union itself.  All members of the union
  139.      must have the same machine representation; this is necessary for
  140.      this argument passing to work properly.
  141.      Transparent unions are designed for library functions that have
  142.      multiple interfaces for compatibility reasons.  For example,
  143.      suppose the `wait' function must accept either a value of type
  144.      `int *' to comply with Posix, or a value of type `union wait *' to
  145.      comply with the 4.1BSD interface.  If `wait''s parameter were
  146.      `void *', `wait' would accept both kinds of arguments, but it
  147.      would also accept any other pointer type and this would make
  148.      argument type checking less useful.  Instead, `<sys/wait.h>' might
  149.      define the interface as follows:
  150.           typedef union
  151.             {
  152.               int *__ip;
  153.               union wait *__up;
  154.             } wait_status_ptr_t __attribute__ ((__transparent_union__));
  155.           
  156.           pid_t wait (wait_status_ptr_t);
  157.      This interface allows either `int *' or `union wait *' arguments
  158.      to be passed, using the `int *' calling convention.  The program
  159.      can call `wait' with arguments of either type:
  160.           int w1 () { int w; return wait (&w); }
  161.           int w2 () { union wait w; return wait (&w); }
  162.      With this interface, `wait''s implementation might look like this:
  163.           pid_t wait (wait_status_ptr_t p)
  164.           {
  165.             return waitpid (-1, p.__ip, 0);
  166.           }
  167. `unused'
  168.      When attached to a type (including a `union' or a `struct'), this
  169.      attribute means that variables of that type are meant to appear
  170.      possibly unused.  GNU CC will not produce a warning for any
  171.      variables of that type, even if the variable appears to do
  172.      nothing.  This is often the case with lock or thread classes,
  173.      which are usually defined and then not referenced, but contain
  174.      constructors and destructors that have nontrivial bookkeeping
  175.      functions.
  176.    To specify multiple attributes, separate them by commas within the
  177. double parentheses: for example, `__attribute__ ((aligned (16),
  178. packed))'.
  179. File: gcc.info,  Node: Inline,  Next: Extended Asm,  Prev: Alignment,  Up: C Extensions
  180. An Inline Function is As Fast As a Macro
  181. ========================================
  182.    By declaring a function `inline', you can direct GNU CC to integrate
  183. that function's code into the code for its callers.  This makes
  184. execution faster by eliminating the function-call overhead; in
  185. addition, if any of the actual argument values are constant, their known
  186. values may permit simplifications at compile time so that not all of the
  187. inline function's code needs to be included.  The effect on code size is
  188. less predictable; object code may be larger or smaller with function
  189. inlining, depending on the particular case.  Inlining of functions is an
  190. optimization and it really "works" only in optimizing compilation.  If
  191. you don't use `-O', no function is really inline.
  192.    To declare a function inline, use the `inline' keyword in its
  193. declaration, like this:
  194.      inline int
  195.      inc (int *a)
  196.      {
  197.        (*a)++;
  198.      }
  199.    (If you are writing a header file to be included in ANSI C programs,
  200. write `__inline__' instead of `inline'.  *Note Alternate Keywords::.)
  201. You can also make all "simple enough" functions inline with the option
  202. `-finline-functions'.
  203.    Note that certain usages in a function definition can make it
  204. unsuitable for inline substitution.  Among these usages are: use of
  205. varargs, use of alloca, use of variable sized data types (*note
  206. Variable Length::.), use of computed goto (*note Labels as Values::.),
  207. use of nonlocal goto, and nested functions (*note Nested Functions::.).
  208. Using `-Winline' will warn when a function marked `inline' could not
  209. be substituted, and will give the reason for the failure.
  210.    Note that in C and Objective C, unlike C++, the `inline' keyword
  211. does not affect the linkage of the function.
  212.    GNU CC automatically inlines member functions defined within the
  213. class body of C++ programs even if they are not explicitly declared
  214. `inline'.  (You can override this with `-fno-default-inline'; *note
  215. Options Controlling C++ Dialect: C++ Dialect Options..)
  216.    When a function is both inline and `static', if all calls to the
  217. function are integrated into the caller, and the function's address is
  218. never used, then the function's own assembler code is never referenced.
  219. In this case, GNU CC does not actually output assembler code for the
  220. function, unless you specify the option `-fkeep-inline-functions'.
  221. Some calls cannot be integrated for various reasons (in particular,
  222. calls that precede the function's definition cannot be integrated, and
  223. neither can recursive calls within the definition).  If there is a
  224. nonintegrated call, then the function is compiled to assembler code as
  225. usual.  The function must also be compiled as usual if the program
  226. refers to its address, because that can't be inlined.
  227.    When an inline function is not `static', then the compiler must
  228. assume that there may be calls from other source files; since a global
  229. symbol can be defined only once in any program, the function must not
  230. be defined in the other source files, so the calls therein cannot be
  231. integrated.  Therefore, a non-`static' inline function is always
  232. compiled on its own in the usual fashion.
  233.    If you specify both `inline' and `extern' in the function
  234. definition, then the definition is used only for inlining.  In no case
  235. is the function compiled on its own, not even if you refer to its
  236. address explicitly.  Such an address becomes an external reference, as
  237. if you had only declared the function, and had not defined it.
  238.    This combination of `inline' and `extern' has almost the effect of a
  239. macro.  The way to use it is to put a function definition in a header
  240. file with these keywords, and put another copy of the definition
  241. (lacking `inline' and `extern') in a library file.  The definition in
  242. the header file will cause most calls to the function to be inlined.
  243. If any uses of the function remain, they will refer to the single copy
  244. in the library.
  245.    GNU C does not inline any functions when not optimizing.  It is not
  246. clear whether it is better to inline or not, in this case, but we found
  247. that a correct implementation when not optimizing was difficult.  So we
  248. did the easy thing, and turned it off.
  249. File: gcc.info,  Node: Extended Asm,  Next: Asm Labels,  Prev: Inline,  Up: C Extensions
  250. Assembler Instructions with C Expression Operands
  251. =================================================
  252.    In an assembler instruction using `asm', you can specify the
  253. operands of the instruction using C expressions.  This means you need
  254. not guess which registers or memory locations will contain the data you
  255. want to use.
  256.    You must specify an assembler instruction template much like what
  257. appears in a machine description, plus an operand constraint string for
  258. each operand.
  259.    For example, here is how to use the 68881's `fsinx' instruction:
  260.      asm ("fsinx %1,%0" : "=f" (result) : "f" (angle));
  261. Here `angle' is the C expression for the input operand while `result'
  262. is that of the output operand.  Each has `"f"' as its operand
  263. constraint, saying that a floating point register is required.  The `='
  264. in `=f' indicates that the operand is an output; all output operands'
  265. constraints must use `='.  The constraints use the same language used
  266. in the machine description (*note Constraints::.).
  267.    Each operand is described by an operand-constraint string followed by
  268. the C expression in parentheses.  A colon separates the assembler
  269. template from the first output operand and another separates the last
  270. output operand from the first input, if any.  Commas separate the
  271. operands within each group.  The total number of operands is limited to
  272. ten or to the maximum number of operands in any instruction pattern in
  273. the machine description, whichever is greater.
  274.    If there are no output operands but there are input operands, you
  275. must place two consecutive colons surrounding the place where the output
  276. operands would go.
  277.    Output operand expressions must be lvalues; the compiler can check
  278. this.  The input operands need not be lvalues.  The compiler cannot
  279. check whether the operands have data types that are reasonable for the
  280. instruction being executed.  It does not parse the assembler instruction
  281. template and does not know what it means or even whether it is valid
  282. assembler input.  The extended `asm' feature is most often used for
  283. machine instructions the compiler itself does not know exist.  If the
  284. output expression cannot be directly addressed (for example, it is a
  285. bit field), your constraint must allow a register.  In that case, GNU CC
  286. will use the register as the output of the `asm', and then store that
  287. register into the output.
  288.    The ordinary output operands must be write-only; GNU CC will assume
  289. that the values in these operands before the instruction are dead and
  290. need not be generated.  Extended asm supports input-output or read-write
  291. operands.  Use the constraint character `+' to indicate such an operand
  292. and list it with the output operands.
  293.    When the constraints for the read-write operand (or the operand in
  294. which only some of the bits are to be changed) allows a register, you
  295. may, as an alternative, logically split its function into two separate
  296. operands, one input operand and one write-only output operand.  The
  297. connection between them is expressed by constraints which say they need
  298. to be in the same location when the instruction executes.  You can use
  299. the same C expression for both operands, or different expressions.  For
  300. example, here we write the (fictitious) `combine' instruction with
  301. `bar' as its read-only source operand and `foo' as its read-write
  302. destination:
  303.      asm ("combine %2,%0" : "=r" (foo) : "0" (foo), "g" (bar));
  304. The constraint `"0"' for operand 1 says that it must occupy the same
  305. location as operand 0.  A digit in constraint is allowed only in an
  306. input operand and it must refer to an output operand.
  307.    Only a digit in the constraint can guarantee that one operand will
  308. be in the same place as another.  The mere fact that `foo' is the value
  309. of both operands is not enough to guarantee that they will be in the
  310. same place in the generated assembler code.  The following would not
  311. work reliably:
  312.      asm ("combine %2,%0" : "=r" (foo) : "r" (foo), "g" (bar));
  313.    Various optimizations or reloading could cause operands 0 and 1 to
  314. be in different registers; GNU CC knows no reason not to do so.  For
  315. example, the compiler might find a copy of the value of `foo' in one
  316. register and use it for operand 1, but generate the output operand 0 in
  317. a different register (copying it afterward to `foo''s own address).  Of
  318. course, since the register for operand 1 is not even mentioned in the
  319. assembler code, the result will not work, but GNU CC can't tell that.
  320.    Some instructions clobber specific hard registers.  To describe this,
  321. write a third colon after the input operands, followed by the names of
  322. the clobbered hard registers (given as strings).  Here is a realistic
  323. example for the VAX:
  324.      asm volatile ("movc3 %0,%1,%2"
  325.                    : /* no outputs */
  326.                    : "g" (from), "g" (to), "g" (count)
  327.                    : "r0", "r1", "r2", "r3", "r4", "r5");
  328.    It is an error for a clobber description to overlap an input or
  329. output operand (for example, an operand describing a register class
  330. with one member, mentioned in the clobber list).  Most notably, it is
  331. invalid to describe that an input operand is modified, but unused as
  332. output.  It has to be specified as an input and output operand anyway.
  333. Note that if there are only unused output operands, you will then also
  334. need to specify `volatile' for the `asm' construct, as described below.
  335.    If you refer to a particular hardware register from the assembler
  336. code, you will probably have to list the register after the third colon
  337. to tell the compiler the register's value is modified.  In some
  338. assemblers, the register names begin with `%'; to produce one `%' in the
  339. assembler code, you must write `%%' in the input.
  340.    If your assembler instruction can alter the condition code register,
  341. add `cc' to the list of clobbered registers.  GNU CC on some machines
  342. represents the condition codes as a specific hardware register; `cc'
  343. serves to name this register.  On other machines, the condition code is
  344. handled differently, and specifying `cc' has no effect.  But it is
  345. valid no matter what the machine.
  346.    If your assembler instruction modifies memory in an unpredictable
  347. fashion, add `memory' to the list of clobbered registers.  This will
  348. cause GNU CC to not keep memory values cached in registers across the
  349. assembler instruction.
  350.    You can put multiple assembler instructions together in a single
  351. `asm' template, separated either with newlines (written as `\n') or
  352. with semicolons if the assembler allows such semicolons.  The GNU
  353. assembler allows semicolons and most Unix assemblers seem to do so.
  354. The input operands are guaranteed not to use any of the clobbered
  355. registers, and neither will the output operands' addresses, so you can
  356. read and write the clobbered registers as many times as you like.  Here
  357. is an example of multiple instructions in a template; it assumes the
  358. subroutine `_foo' accepts arguments in registers 9 and 10:
  359.      asm ("movl %0,r9;movl %1,r10;call _foo"
  360.           : /* no outputs */
  361.           : "g" (from), "g" (to)
  362.           : "r9", "r10");
  363.    Unless an output operand has the `&' constraint modifier, GNU CC may
  364. allocate it in the same register as an unrelated input operand, on the
  365. assumption the inputs are consumed before the outputs are produced.
  366. This assumption may be false if the assembler code actually consists of
  367. more than one instruction.  In such a case, use `&' for each output
  368. operand that may not overlap an input.  *Note Modifiers::.
  369.    If you want to test the condition code produced by an assembler
  370. instruction, you must include a branch and a label in the `asm'
  371. construct, as follows:
  372.      asm ("clr %0;frob %1;beq 0f;mov #1,%0;0:"
  373.           : "g" (result)
  374.           : "g" (input));
  375. This assumes your assembler supports local labels, as the GNU assembler
  376. and most Unix assemblers do.
  377.    Speaking of labels, jumps from one `asm' to another are not
  378. supported.  The compiler's optimizers do not know about these jumps, and
  379. therefore they cannot take account of them when deciding how to
  380. optimize.
  381.    Usually the most convenient way to use these `asm' instructions is to
  382. encapsulate them in macros that look like functions.  For example,
  383.      #define sin(x)       \
  384.      ({ double __value, __arg = (x);   \
  385.         asm ("fsinx %1,%0": "=f" (__value): "f" (__arg));  \
  386.         __value; })
  387. Here the variable `__arg' is used to make sure that the instruction
  388. operates on a proper `double' value, and to accept only those arguments
  389. `x' which can convert automatically to a `double'.
  390.    Another way to make sure the instruction operates on the correct data
  391. type is to use a cast in the `asm'.  This is different from using a
  392. variable `__arg' in that it converts more different types.  For
  393. example, if the desired type were `int', casting the argument to `int'
  394. would accept a pointer with no complaint, while assigning the argument
  395. to an `int' variable named `__arg' would warn about using a pointer
  396. unless the caller explicitly casts it.
  397.    If an `asm' has output operands, GNU CC assumes for optimization
  398. purposes the instruction has no side effects except to change the output
  399. operands.  This does not mean instructions with a side effect cannot be
  400. used, but you must be careful, because the compiler may eliminate them
  401. if the output operands aren't used, or move them out of loops, or
  402. replace two with one if they constitute a common subexpression.  Also,
  403. if your instruction does have a side effect on a variable that otherwise
  404. appears not to change, the old value of the variable may be reused later
  405. if it happens to be found in a register.
  406.    You can prevent an `asm' instruction from being deleted, moved
  407. significantly, or combined, by writing the keyword `volatile' after the
  408. `asm'.  For example:
  409.      #define get_and_set_priority(new)  \
  410.      ({ int __old; \
  411.         asm volatile ("get_and_set_priority %0, %1": "=g" (__old) : "g" (new)); \
  412.         __old; })
  413. If you write an `asm' instruction with no outputs, GNU CC will know the
  414. instruction has side-effects and will not delete the instruction or
  415. move it outside of loops.  If the side-effects of your instruction are
  416. not purely external, but will affect variables in your program in ways
  417. other than reading the inputs and clobbering the specified registers or
  418. memory, you should write the `volatile' keyword to prevent future
  419. versions of GNU CC from moving the instruction around within a core
  420. region.
  421.    An `asm' instruction without any operands or clobbers (and "old
  422. style" `asm') will not be deleted or moved significantly, regardless,
  423. unless it is unreachable, the same wasy as if you had written a
  424. `volatile' keyword.
  425.    Note that even a volatile `asm' instruction can be moved in ways
  426. that appear insignificant to the compiler, such as across jump
  427. instructions.  You can't expect a sequence of volatile `asm'
  428. instructions to remain perfectly consecutive.  If you want consecutive
  429. output, use a single `asm'.
  430.    It is a natural idea to look for a way to give access to the
  431. condition code left by the assembler instruction.  However, when we
  432. attempted to implement this, we found no way to make it work reliably.
  433. The problem is that output operands might need reloading, which would
  434. result in additional following "store" instructions.  On most machines,
  435. these instructions would alter the condition code before there was time
  436. to test it.  This problem doesn't arise for ordinary "test" and
  437. "compare" instructions because they don't have any output operands.
  438.    If you are writing a header file that should be includable in ANSI C
  439. programs, write `__asm__' instead of `asm'.  *Note Alternate Keywords::.
  440. i386 floating point asm operands
  441. --------------------------------
  442.    There are several rules on the usage of stack-like regs in
  443. asm_operands insns.  These rules apply only to the operands that are
  444. stack-like regs:
  445.   1. Given a set of input regs that die in an asm_operands, it is
  446.      necessary to know which are implicitly popped by the asm, and
  447.      which must be explicitly popped by gcc.
  448.      An input reg that is implicitly popped by the asm must be
  449.      explicitly clobbered, unless it is constrained to match an output
  450.      operand.
  451.   2. For any input reg that is implicitly popped by an asm, it is
  452.      necessary to know how to adjust the stack to compensate for the
  453.      pop.  If any non-popped input is closer to the top of the
  454.      reg-stack than the implicitly popped reg, it would not be possible
  455.      to know what the stack looked like -- it's not clear how the rest
  456.      of the stack "slides up".
  457.      All implicitly popped input regs must be closer to the top of the
  458.      reg-stack than any input that is not implicitly popped.
  459.      It is possible that if an input dies in an insn, reload might use
  460.      the input reg for an output reload.  Consider this example:
  461.           asm ("foo" : "=t" (a) : "f" (b));
  462.      This asm says that input B is not popped by the asm, and that the
  463.      asm pushes a result onto the reg-stack, ie, the stack is one
  464.      deeper after the asm than it was before.  But, it is possible that
  465.      reload will think that it can use the same reg for both the input
  466.      and the output, if input B dies in this insn.
  467.      If any input operand uses the `f' constraint, all output reg
  468.      constraints must use the `&' earlyclobber.
  469.      The asm above would be written as
  470.           asm ("foo" : "=&t" (a) : "f" (b));
  471.   3. Some operands need to be in particular places on the stack.  All
  472.      output operands fall in this category -- there is no other way to
  473.      know which regs the outputs appear in unless the user indicates
  474.      this in the constraints.
  475.      Output operands must specifically indicate which reg an output
  476.      appears in after an asm.  `=f' is not allowed: the operand
  477.      constraints must select a class with a single reg.
  478.   4. Output operands may not be "inserted" between existing stack regs.
  479.      Since no 387 opcode uses a read/write operand, all output operands
  480.      are dead before the asm_operands, and are pushed by the
  481.      asm_operands.  It makes no sense to push anywhere but the top of
  482.      the reg-stack.
  483.      Output operands must start at the top of the reg-stack: output
  484.      operands may not "skip" a reg.
  485.   5. Some asm statements may need extra stack space for internal
  486.      calculations.  This can be guaranteed by clobbering stack registers
  487.      unrelated to the inputs and outputs.
  488.    Here are a couple of reasonable asms to want to write.  This asm
  489. takes one input, which is internally popped, and produces two outputs.
  490.      asm ("fsincos" : "=t" (cos), "=u" (sin) : "0" (inp));
  491.    This asm takes two inputs, which are popped by the `fyl2xp1' opcode,
  492. and replaces them with one output.  The user must code the `st(1)'
  493. clobber for reg-stack.c to know that `fyl2xp1' pops both inputs.
  494.      asm ("fyl2xp1" : "=t" (result) : "0" (x), "u" (y) : "st(1)");
  495. File: gcc.info,  Node: Asm Labels,  Next: Explicit Reg Vars,  Prev: Extended Asm,  Up: C Extensions
  496. Controlling Names Used in Assembler Code
  497. ========================================
  498.    You can specify the name to be used in the assembler code for a C
  499. function or variable by writing the `asm' (or `__asm__') keyword after
  500. the declarator as follows:
  501.      int foo asm ("myfoo") = 2;
  502. This specifies that the name to be used for the variable `foo' in the
  503. assembler code should be `myfoo' rather than the usual `_foo'.
  504.    On systems where an underscore is normally prepended to the name of
  505. a C function or variable, this feature allows you to define names for
  506. the linker that do not start with an underscore.
  507.    You cannot use `asm' in this way in a function *definition*; but you
  508. can get the same effect by writing a declaration for the function
  509. before its definition and putting `asm' there, like this:
  510.      extern func () asm ("FUNC");
  511.      
  512.      func (x, y)
  513.           int x, y;
  514.      ...
  515.    It is up to you to make sure that the assembler names you choose do
  516. not conflict with any other assembler symbols.  Also, you must not use a
  517. register name; that would produce completely invalid assembler code.
  518. GNU CC does not as yet have the ability to store static variables in
  519. registers.  Perhaps that will be added.
  520. File: gcc.info,  Node: Explicit Reg Vars,  Next: Alternate Keywords,  Prev: Asm Labels,  Up: C Extensions
  521. Variables in Specified Registers
  522. ================================
  523.    GNU C allows you to put a few global variables into specified
  524. hardware registers.  You can also specify the register in which an
  525. ordinary register variable should be allocated.
  526.    * Global register variables reserve registers throughout the program.
  527.      This may be useful in programs such as programming language
  528.      interpreters which have a couple of global variables that are
  529.      accessed very often.
  530.    * Local register variables in specific registers do not reserve the
  531.      registers.  The compiler's data flow analysis is capable of
  532.      determining where the specified registers contain live values, and
  533.      where they are available for other uses.  Stores into local
  534.      register variables may be deleted when they appear to be dead
  535.      according to dataflow analysis.  References to local register
  536.      variables may be deleted or moved or simplified.
  537.      These local variables are sometimes convenient for use with the
  538.      extended `asm' feature (*note Extended Asm::.), if you want to
  539.      write one output of the assembler instruction directly into a
  540.      particular register.  (This will work provided the register you
  541.      specify fits the constraints specified for that operand in the
  542.      `asm'.)
  543. * Menu:
  544. * Global Reg Vars::
  545. * Local Reg Vars::
  546. File: gcc.info,  Node: Global Reg Vars,  Next: Local Reg Vars,  Up: Explicit Reg Vars
  547. Defining Global Register Variables
  548. ----------------------------------
  549.    You can define a global register variable in GNU C like this:
  550.      register int *foo asm ("a5");
  551. Here `a5' is the name of the register which should be used.  Choose a
  552. register which is normally saved and restored by function calls on your
  553. machine, so that library routines will not clobber it.
  554.    Naturally the register name is cpu-dependent, so you would need to
  555. conditionalize your program according to cpu type.  The register `a5'
  556. would be a good choice on a 68000 for a variable of pointer type.  On
  557. machines with register windows, be sure to choose a "global" register
  558. that is not affected magically by the function call mechanism.
  559.    In addition, operating systems on one type of cpu may differ in how
  560. they name the registers; then you would need additional conditionals.
  561. For example, some 68000 operating systems call this register `%a5'.
  562.    Eventually there may be a way of asking the compiler to choose a
  563. register automatically, but first we need to figure out how it should
  564. choose and how to enable you to guide the choice.  No solution is
  565. evident.
  566.    Defining a global register variable in a certain register reserves
  567. that register entirely for this use, at least within the current
  568. compilation.  The register will not be allocated for any other purpose
  569. in the functions in the current compilation.  The register will not be
  570. saved and restored by these functions.  Stores into this register are
  571. never deleted even if they would appear to be dead, but references may
  572. be deleted or moved or simplified.
  573.    It is not safe to access the global register variables from signal
  574. handlers, or from more than one thread of control, because the system
  575. library routines may temporarily use the register for other things
  576. (unless you recompile them specially for the task at hand).
  577.    It is not safe for one function that uses a global register variable
  578. to call another such function `foo' by way of a third function `lose'
  579. that was compiled without knowledge of this variable (i.e. in a
  580. different source file in which the variable wasn't declared).  This is
  581. because `lose' might save the register and put some other value there.
  582. For example, you can't expect a global register variable to be
  583. available in the comparison-function that you pass to `qsort', since
  584. `qsort' might have put something else in that register.  (If you are
  585. prepared to recompile `qsort' with the same global register variable,
  586. you can solve this problem.)
  587.    If you want to recompile `qsort' or other source files which do not
  588. actually use your global register variable, so that they will not use
  589. that register for any other purpose, then it suffices to specify the
  590. compiler option `-ffixed-REG'.  You need not actually add a global
  591. register declaration to their source code.
  592.    A function which can alter the value of a global register variable
  593. cannot safely be called from a function compiled without this variable,
  594. because it could clobber the value the caller expects to find there on
  595. return.  Therefore, the function which is the entry point into the part
  596. of the program that uses the global register variable must explicitly
  597. save and restore the value which belongs to its caller.
  598.    On most machines, `longjmp' will restore to each global register
  599. variable the value it had at the time of the `setjmp'.  On some
  600. machines, however, `longjmp' will not change the value of global
  601. register variables.  To be portable, the function that called `setjmp'
  602. should make other arrangements to save the values of the global register
  603. variables, and to restore them in a `longjmp'.  This way, the same
  604. thing will happen regardless of what `longjmp' does.
  605.    All global register variable declarations must precede all function
  606. definitions.  If such a declaration could appear after function
  607. definitions, the declaration would be too late to prevent the register
  608. from being used for other purposes in the preceding functions.
  609.    Global register variables may not have initial values, because an
  610. executable file has no means to supply initial contents for a register.
  611.    On the Sparc, there are reports that g3 ... g7 are suitable
  612. registers, but certain library functions, such as `getwd', as well as
  613. the subroutines for division and remainder, modify g3 and g4.  g1 and
  614. g2 are local temporaries.
  615.    On the 68000, a2 ... a5 should be suitable, as should d2 ... d7.  Of
  616. course, it will not do to use more than a few of those.
  617. File: gcc.info,  Node: Local Reg Vars,  Prev: Global Reg Vars,  Up: Explicit Reg Vars
  618. Specifying Registers for Local Variables
  619. ----------------------------------------
  620.    You can define a local register variable with a specified register
  621. like this:
  622.      register int *foo asm ("a5");
  623. Here `a5' is the name of the register which should be used.  Note that
  624. this is the same syntax used for defining global register variables,
  625. but for a local variable it would appear within a function.
  626.    Naturally the register name is cpu-dependent, but this is not a
  627. problem, since specific registers are most often useful with explicit
  628. assembler instructions (*note Extended Asm::.).  Both of these things
  629. generally require that you conditionalize your program according to cpu
  630. type.
  631.    In addition, operating systems on one type of cpu may differ in how
  632. they name the registers; then you would need additional conditionals.
  633. For example, some 68000 operating systems call this register `%a5'.
  634.    Defining such a register variable does not reserve the register; it
  635. remains available for other uses in places where flow control determines
  636. the variable's value is not live.  However, these registers are made
  637. unavailable for use in the reload pass; excessive use of this feature
  638. leaves the compiler too few available registers to compile certain
  639. functions.
  640.    This option does not guarantee that GNU CC will generate code that
  641. has this variable in the register you specify at all times.  You may not
  642. code an explicit reference to this register in an `asm' statement and
  643. assume it will always refer to this variable.
  644.    Stores into local register variables may be deleted when they appear
  645. to be dead according to dataflow analysis.  References to local
  646. register variables may be deleted or moved or simplified.
  647. File: gcc.info,  Node: Alternate Keywords,  Next: Incomplete Enums,  Prev: Explicit Reg Vars,  Up: C Extensions
  648. Alternate Keywords
  649. ==================
  650.    The option `-traditional' disables certain keywords; `-ansi'
  651. disables certain others.  This causes trouble when you want to use GNU C
  652. extensions, or ANSI C features, in a general-purpose header file that
  653. should be usable by all programs, including ANSI C programs and
  654. traditional ones.  The keywords `asm', `typeof' and `inline' cannot be
  655. used since they won't work in a program compiled with `-ansi', while
  656. the keywords `const', `volatile', `signed', `typeof' and `inline' won't
  657. work in a program compiled with `-traditional'.
  658.    The way to solve these problems is to put `__' at the beginning and
  659. end of each problematical keyword.  For example, use `__asm__' instead
  660. of `asm', `__const__' instead of `const', and `__inline__' instead of
  661. `inline'.
  662.    Other C compilers won't accept these alternative keywords; if you
  663. want to compile with another compiler, you can define the alternate
  664. keywords as macros to replace them with the customary keywords.  It
  665. looks like this:
  666.      #ifndef __GNUC__
  667.      #define __asm__ asm
  668.      #endif
  669.    `-pedantic' causes warnings for many GNU C extensions.  You can
  670. prevent such warnings within one expression by writing `__extension__'
  671. before the expression.  `__extension__' has no effect aside from this.
  672. File: gcc.info,  Node: Incomplete Enums,  Next: Function Names,  Prev: Alternate Keywords,  Up: C Extensions
  673. Incomplete `enum' Types
  674. =======================
  675.    You can define an `enum' tag without specifying its possible values.
  676. This results in an incomplete type, much like what you get if you write
  677. `struct foo' without describing the elements.  A later declaration
  678. which does specify the possible values completes the type.
  679.    You can't allocate variables or storage using the type while it is
  680. incomplete.  However, you can work with pointers to that type.
  681.    This extension may not be very useful, but it makes the handling of
  682. `enum' more consistent with the way `struct' and `union' are handled.
  683.    This extension is not supported by GNU C++.
  684. File: gcc.info,  Node: Function Names,  Next: Return Address,  Prev: Incomplete Enums,  Up: C Extensions
  685. Function Names as Strings
  686. =========================
  687.    GNU CC predefines two string variables to be the name of the current
  688. function.  The variable `__FUNCTION__' is the name of the function as
  689. it appears in the source.  The variable `__PRETTY_FUNCTION__' is the
  690. name of the function pretty printed in a language specific fashion.
  691.    These names are always the same in a C function, but in a C++
  692. function they may be different.  For example, this program:
  693.      extern "C" {
  694.      extern int printf (char *, ...);
  695.      }
  696.      
  697.      class a {
  698.       public:
  699.        sub (int i)
  700.          {
  701.            printf ("__FUNCTION__ = %s\n", __FUNCTION__);
  702.            printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
  703.          }
  704.      };
  705.      
  706.      int
  707.      main (void)
  708.      {
  709.        a ax;
  710.        ax.sub (0);
  711.        return 0;
  712.      }
  713. gives this output:
  714.      __FUNCTION__ = sub
  715.      __PRETTY_FUNCTION__ = int  a::sub (int)
  716.    These names are not macros: they are predefined string variables.
  717. For example, `#ifdef __FUNCTION__' does not have any special meaning
  718. inside a function, since the preprocessor does not do anything special
  719. with the identifier `__FUNCTION__'.
  720. File: gcc.info,  Node: Return Address,  Next: Other Builtins,  Prev: Function Names,  Up: C Extensions
  721. Getting the Return or Frame Address of a Function
  722. =================================================
  723.    These functions may be used to get information about the callers of a
  724. function.
  725. `__builtin_return_address (LEVEL)'
  726.      This function returns the return address of the current function,
  727.      or of one of its callers.  The LEVEL argument is number of frames
  728.      to scan up the call stack.  A value of `0' yields the return
  729.      address of the current function, a value of `1' yields the return
  730.      address of the caller of the current function, and so forth.
  731.      The LEVEL argument must be a constant integer.
  732.      On some machines it may be impossible to determine the return
  733.      address of any function other than the current one; in such cases,
  734.      or when the top of the stack has been reached, this function will
  735.      return `0'.
  736.      This function should only be used with a non-zero argument for
  737.      debugging purposes.
  738. `__builtin_frame_address (LEVEL)'
  739.      This function is similar to `__builtin_return_address', but it
  740.      returns the address of the function frame rather than the return
  741.      address of the function.  Calling `__builtin_frame_address' with a
  742.      value of `0' yields the frame address of the current function, a
  743.      value of `1' yields the frame address of the caller of the current
  744.      function, and so forth.
  745.      The frame is the area on the stack which holds local variables and
  746.      saved registers.  The frame address is normally the address of the
  747.      first word pushed on to the stack by the function.  However, the
  748.      exact definition depends upon the processor and the calling
  749.      convention.  If the processor has a dedicated frame pointer
  750.      register, and the function has a frame, then
  751.      `__builtin_frame_address' will return the value of the frame
  752.      pointer register.
  753.      The caveats that apply to `__builtin_return_address' apply to this
  754.      function as well.
  755. File: gcc.info,  Node: Other Builtins,  Next: Deprecated Features,  Prev: Return Address,  Up: C Extensions
  756. Other built-in functions provided by GNU CC
  757. ===========================================
  758.    GNU CC provides a large number of built-in functions other than the
  759. ones mentioned above.  Some of these are for internal use in the
  760. processing of exceptions or variable-length argument lists and will not
  761. be documented here because they may change from time to time; we do not
  762. recommend general use of these functions.
  763.    The remaining functions are provided for optimization purposes.
  764.    GNU CC includes builtin versions of many of the functions in the
  765. standard C library.  These will always be treated as having the same
  766. meaning as the C library function even if you specify the
  767. `-fno-builtin' (*note C Dialect Options::.) option.  These functions
  768. correspond to the C library functions `alloca', `ffs', `abs', `fabsf',
  769. `fabs', `fabsl', `labs', `memcpy', `memcmp', `strcmp', `strcpy',
  770. `strlen', `sqrtf', `sqrt', `sqrtl', `sinf', `sin', `sinl', `cosf',
  771. `cos', and `cosl'.
  772.    You can use the builtin function `__builtin_constant_p' to determine
  773. if a value is known to be constant at compile-time and hence that GNU
  774. CC can perform constant-folding on expressions involving that value.
  775. The argument of the function is the value to test.  The function
  776. returns the integer 1 if the argument is known to be a compile-time
  777. constant and 0 if it is not known to be a compile-time constant.  A
  778. return of 0 does not indicate that the value is *not* a constant, but
  779. merely that GNU CC cannot prove it is a constant with the specified
  780. value of the `-O' option.
  781.    You would typically use this function in an embedded application
  782. where memory was a critical resource.  If you have some complex
  783. calculation, you may want it to be folded if it involves constants, but
  784. need to call a function if it does not.  For example:
  785.      #define Scale_Value(X)  \
  786.        (__builtin_constant_p (X) ? ((X) * SCALE + OFFSET) : Scale (X))
  787.    You may use this builtin function in either a macro or an inline
  788. function.  However, if you use it in an inlined function and pass an
  789. argument of the function as the argument to the builtin, GNU CC will
  790. never return 1 when you call the inline function with a string constant
  791. or constructor expression (*note Constructors::.) and will not return 1
  792. when you pass a constant numeric value to the inline function unless you
  793. specify the `-O' option.
  794. File: gcc.info,  Node: Deprecated Features,  Prev: Other Builtins,  Up: C Extensions
  795. Deprecated Features
  796. ===================
  797.    In the past, the GNU C++ compiler was extended to experiment with new
  798. features, at a time when the C++ language was still evolving. Now that
  799. the C++ standard is complete, some of those features are superceded by
  800. superior alternatives. Using the old features might cause a warning in
  801. some cases that the feature will be dropped in the future. In other
  802. cases, the feature might be gone already.
  803.    While the list below is not exhaustive, it documents some of the
  804. options that are now deprecated:
  805. `-fthis-is-variable'
  806.      In early versions of C++, assignment to this could be used to
  807.      implement application-defined memory allocation. Now, allocation
  808.      functions (`operator new') are the standard-conforming way to
  809.      achieve the same effect.
  810. `-fexternal-templates'
  811. `-falt-external-templates'
  812.      These are two of the many ways for g++ to implement template
  813.      instantiation. *Note Template Instantiation::. The C++ standard
  814.      clearly defines how template definitions have to be organized
  815.      across implementation units. g++ has an implicit instantiation
  816.      mechanism that should work just fine for standard-conforming code.
  817. File: gcc.info,  Node: C++ Extensions,  Next: Gcov,  Prev: C Extensions,  Up: Top
  818. Extensions to the C++ Language
  819. ******************************
  820.    The GNU compiler provides these extensions to the C++ language (and
  821. you can also use most of the C language extensions in your C++
  822. programs).  If you want to write code that checks whether these
  823. features are available, you can test for the GNU compiler the same way
  824. as for C programs: check for a predefined macro `__GNUC__'.  You can
  825. also use `__GNUG__' to test specifically for GNU C++ (*note Standard
  826. Predefined Macros: (cpp.info)Standard Predefined.).
  827. * Menu:
  828. * Naming Results::      Giving a name to C++ function return values.
  829. * Min and Max::        C++ Minimum and maximum operators.
  830. * Destructors and Goto:: Goto is safe to use in C++ even when destructors
  831.                            are needed.
  832. * C++ Interface::       You can use a single C++ header file for both
  833.                          declarations and definitions.
  834. * Template Instantiation:: Methods for ensuring that exactly one copy of
  835.                          each needed template instantiation is emitted.
  836. * Bound member functions:: You can extract a function pointer to the
  837.                         method denoted by a `->*' or `.*' expression.
  838. * C++ Signatures::    You can specify abstract types to get subtype
  839.              polymorphism independent from inheritance.
  840.